package person.bing.fbcloud.leetcode;

/**
 * @author: mengfanbing
 * @date: 2020/12/29 10:12
 */
public class Q38 {
    public static void main(String[] args) {

    }

    public static String countAndSay(int n) {
        if (n == 1){
            return "1";
        }else {
            return getTemp(countAndSay(n-1));
        }

    }

    public static String getTemp(String value){
        StringBuilder sb = new StringBuilder();
        char[] valueCharArray = value.toCharArray();
        char lastChar = 0;
        int count = 0;
        for (char valueChar:valueCharArray){
            if (lastChar == 0){
                count++;
            }else {
                if (valueChar == lastChar){
                    count++;
                }else {
                    sb.append(count).append(lastChar);
                    count = 1;
                }
            }
            lastChar = valueChar;
        }
        sb.append(count).append(lastChar);
        return sb.toString();
    }
}
